package Com.Isman.Booking;

import java.util.ArrayList;
import java.util.List;

import Com.Isman.Adapter.HotelOrderAdapter;
import Com.Isman.WebService.NetworkCallOrderListener;
import Com.Isman.WebService.ServiceConnect;
import Com.Isman.WebService.ComplexType.Order;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;

public class PageOrderList extends Activity implements NetworkCallOrderListener {
	
	class NetworkCallOrderListTask extends AsyncTask<String,Void,List<Order>>{
		private NetworkCallOrderListener listener = null;
		
		public NetworkCallOrderListTask(NetworkCallOrderListener listener) {
			this.listener = listener;
		}
		
		@Override
		protected List<Order> doInBackground(String... str) {
			ServiceConnect sc = new ServiceConnect();
			Log.v("Isman", "doInBackground Orderlist");
			List<Order> d =sc.callGetOrderList(str[0],Integer.parseInt(str[1]),Integer.parseInt(str[2]));
			return d;
		}
		
		@Override
		protected void onPostExecute(List<Order> list) {
		   	listener.onNetworkCallDetailComplete(list);
		   	pbLoadOrder.setVisibility(View.INVISIBLE);
		}
		@Override
		protected void onPreExecute() {
		    super.onPreExecute();
		    pbLoadOrder.setVisibility(View.VISIBLE);
		}
		
	}
	private HotelOrderAdapter adapter;
	
	private List<Order> list = new ArrayList<Order>();
	private ListView lvOrderList;
	
	private ProgressBar pbLoadOrder;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pageorderlist);
		
		pbLoadOrder = (ProgressBar)findViewById(R.id.prbLoadBar);
		lvOrderList = (ListView)findViewById(R.id.lvOrderList);
		
		adapter = new HotelOrderAdapter(this, list);
		lvOrderList.setAdapter(adapter);
		
		new NetworkCallOrderListTask(this).execute(new String[]{"12123123-123123123", "0", "10"});
	}
	@Override
	public void onNetworkCallDetailCancel() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onNetworkCallDetailComplete(List<Order> detail) {
		list.addAll(detail);
		adapter.notifyDataSetChanged();
	}
}
